package Java复习;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;

/*
 * 当以年-月-日的格式输入一个日期时，输出该年是否为闰年，该月有几天，该日是星期几。
 * */
public class Num1 {
    public static void main(String[] args) throws ParseException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个日期：如2023-01-01");
        String str = sc.next();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = sdf.parse(str);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        GregorianCalendar gc = new GregorianCalendar();
        if (gc.isLeapYear(c.get(Calendar.YEAR)))
        {
            System.out.println("是闰年");
        }else {
            System.out.println("是平年");
        }
        System.out.println("该月有" + c.getActualMaximum(Calendar.DAY_OF_MONTH) + "天");
        String[] week = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        System.out.println("今天是" + week[c.get(Calendar.DAY_OF_WEEK)-1]);
    }
}
